package com.smx.controller;

import com.smx.common.CommonResult;
import com.smx.common.IErrorCode;
import com.smx.common.ResultCode;
import com.smx.domain.Student;
import com.smx.service.ChartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Set;

/**
 * @ClassName ChartController
 * @Description TODO
 * @Author moses
 * @Date 2021/8/11
 **/
@RequestMapping("/chart")
@RestController
public class ChartController {

    @Autowired
    private ChartService chartService;

    @GetMapping("/insert")
    public CommonResult<Integer> insertChart() {
        chartService.insertChart(new Student(1,"小明",90));
        chartService.insertChart(new Student(2,"小芳",85));
        chartService.insertChart(new Student(3,"小刚",95));
        return CommonResult.success(1);
    }

    @GetMapping("/list")
    public CommonResult<Set<Object>> listChart() {
        Set<Object> result = chartService.listChart();
        return CommonResult.success(result);
    }

    @DeleteMapping("/{id}")
    public CommonResult<Long> removeChart(@PathVariable int id) {
        Student s = new Student();
        s.setId(id);
        s.setName("小刚");
        s.setScore(95);
        Long result = chartService.removeChart(s);
        if (result > 0) {
            return CommonResult.success(result);
        }
        return CommonResult.failed(ResultCode.FAILED, ResultCode.FAILED.getMessage());
    }
}
